package com.hl.controller;

import com.hl.domain.Consultwait;
import com.hl.service.ConsultwaitService;
import com.hl.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/consultWait")
public class ConsultwaitController {
    @Autowired
    private ConsultwaitService consultwaitService;

    /**
     * 查询所有
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/selectAll")
    public R selectAllConsultWait(int page,int size){
        return R.success(consultwaitService.selectAllConsultWait(page,size));
    }

    /**
     * 咨询预约-分页条件查询
     * @param info
     * @param startDate
     * @param endDate
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/selectByCondition")
    public R selectConsultByCondition(String info, @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate, int page, int size){
        return R.success(consultwaitService.selectConsultByCondition(info,startDate,endDate,page,size));
    }

    /**
     * 删除预约信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public R deleteConsultWaitById(int id){
        return R.success(consultwaitService.deleteConsultWaitById(id));
    }

    //查询状态信息
    @GetMapping("/selectStatus")
    public R selectStatus(){
        return R.success(consultwaitService.selectStatus());
    }

    //根据id修改预约信息
    @PutMapping("/update")
    public R updateConsultWait(@RequestBody @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Consultwait consultwait){
        System.out.println("consultwait.getId() = " + consultwait.getId());
        return R.success(consultwaitService.updateConsultWait(consultwait));
    }


    //发出咨询表
    @PostMapping
    public R addConsultwait(@RequestBody Consultwait consultwait){
        //默认为未完成状态
        consultwait.setStatus(0);
        int row = consultwaitService.addConsult(consultwait);
        return row>0?R.success(1):R.fail(0);
    }


}
